package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.vo.CheckGroupVO;
import com.itheima.health.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SetmealMapper extends BaseMapper<Setmeal> {
    //添加中間表
   @Insert("insert into t_setmeal_checkgroup values(#{sid},#{checkgroupId})")
    void addSetmealAndCheckGroup(@Param("sid") Integer sid,@Param("checkgroupId") Integer checkgroupId);



   //todo:前端 根据套餐id 查询详情
   @Select("select name,sex,age,remark,img " +
           " from t_setmeal " +
           " where id = #{id}")
   SetmealVO findSetMeal(@Param("id") Integer id);

   @Select("select tcp.id, tcp.name,tcp.remark " +
           "from   t_setmeal_checkgroup tsc, t_checkgroup tcp " +
           "where tsc.CHECKGROUP_ID = tcp.id " +
           "and tsc.SETMEAL_ID=#{id}")
   List<CheckGroupVO> findGroupBySetmealId(@Param("id")Integer id);

   @Select("select  tci.name " +
           "from  t_checkgroup_checkitem tcc , t_checkitem tci " +
           "where tcc.CHECKITEM_ID = tci.id " +
           "and tcc.CHECKGROUP_ID = #{id}")
    List<CheckItem> findItemByGroupId(@Param("id")Integer id);

}
